﻿Imports System
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf


Partial Class NewItem
    Inherits System.Web.UI.Page

    Protected Sub TBweight_TextChanged(sender As Object, e As System.EventArgs) Handles TBweight.TextChanged
        Try
            TBcost.Text = Integer.Parse(TBweight.Text) * 1.4
        Catch ex As Exception
            TBweight.Text = ex.ToString
        End Try

    End Sub

    Protected Sub lbtnRecordID_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnRecordID2.Click
        Response.Redirect("~/NewCustomer.aspx?key=2")
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim doc As Document = New Document
        PdfWriter.GetInstance(doc, New FileStream(Request.PhysicalApplicationPath + _
                              "\1.pdf", FileMode.Create))
        doc.Open()
        doc.AddTitle("Receipt")
        doc.Add(New Paragraph("Recepit"))
        doc.Add(New Paragraph("Reference ID: " + "xxxxxxxx"))
        doc.Add(New Paragraph("Destination Type: " + DDLdest.SelectedItem.Text))
        doc.Add(New Paragraph("Item Type: " + DDLItemType.SelectedItem.Text))
        doc.Add(New Paragraph("Weight: " + TBweight.Text))
        doc.Add(New Paragraph("Cost: " + TBcost.Text))
        doc.Add(New Paragraph("Sender: " + DDLItemType0.SelectedItem.Text))
        doc.Add(New Paragraph("Receiver Name: " + TBemail.Text))
        doc.Add(New Paragraph("Receiver Address: " + TBemail0.Text))
        doc.Add(New Paragraph("Receiver Contact: " + TBemail1.Text))
        doc.Close()
        Dim strAddress As String = "./1.pdf"
        Dim newWindowAddress As String = "<script>window.open('" + strAddress + "','_blank');</script>"
        AddCode(newWindowAddress)
        'Response.Redirect("~/1.pdf")

    End Sub
    Private Sub AddCode(ByVal pstrMsg As String)

        Dim lbl As New Label()

        lbl.Text = pstrMsg

        Page.Controls.Add(lbl)

    End Sub

End Class
